import java.util.concurrent.atomic.AtomicInteger;

public class Test1 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger num = new AtomicInteger(0);
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 5_0000; i++) {
                num.getAndIncrement();// 相当于 num++;
            }
        });
        t1.start();
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 5_0000; i++) {
                num.getAndIncrement();// 相当于 num++;
            }
        });

        //++num
        num.incrementAndGet();
        //--num
        num.decrementAndGet();
        //num--
        num.getAndDecrement();
        //+= 10
        num.getAndAdd(10);
        //
        //


        t2.start();
        t1.join();
        t2.join();
        // 通过get方法，来获取原子类内部的数值
        System.out.println(num.get());
    }
}
